package com.sky.controller.user;

import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description：订单
 * @author: ZXX-挚爱
 * @time: 2023/6/12 21:55
 */

@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "C端-订单接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /** @author ZXX-挚爱
    * @Description 用户下单功能接口
    * @Dete 0:38 2023/6/13
    * @Param [ordersSubmitDTO]
    * @return com.sky.result.Result<com.sky.vo.OrderSubmitVO>
    **/

    @PostMapping("/submit")
    @ApiOperation("用户下单功能接口")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("用户下单：{}", ordersSubmitDTO);

        OrderSubmitVO orderSubmitVO=orderService.submitOrder(ordersSubmitDTO);

        return Result.success(orderSubmitVO);
    }

    /** @author ZXX-挚爱
    * @Description 订单支付功能模块
    * @Dete 1:16 2023/6/14
    * @Param [ordersPaymentDTO]
    * @return com.sky.result.Result<com.sky.vo.OrderPaymentVO>
    **/
    
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception{
        log.info("订单支付：{}", ordersPaymentDTO);
        //OrderPaymentVO orderPaymentVO=orderService.payment(ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO=new OrderPaymentVO();
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return  Result.success(orderPaymentVO);
    }

    /** @author ZXX-挚爱
    * @Description 历史订单查询
    * @Dete 15:31 2023/6/14
    * @Param [page, pageSize, status]
    * @return com.sky.result.Result<com.sky.result.PageResult>
    **/

    @GetMapping("/historyOrders")
    @ApiOperation("历史订单查询")
    public Result<PageResult> page(int page,int pageSize,Integer status) {
        PageResult pageResult = orderService.pageQuery(page, pageSize, status);
        return Result.success(pageResult);
    }

    /** @author ZXX-挚爱
    * @Description 查询订单详情
    * @Dete 16:26 2023/6/14
    * @Param [id]
    * @return com.sky.result.Result<com.sky.vo.OrderVO>
    **/

    @GetMapping("/orderDetail/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO>  details(@PathVariable("id") Long id){
        OrderVO orderVO=orderService.details(id);
        return  Result.success(orderVO);
    }

    /** @author ZXX-挚爱
    * @Description 取消订单
    * @Dete 16:31 2023/6/14
    * @Param [id]
    * @return com.sky.result.Result
    **/

    @PutMapping("/cancel/{id}")
    @ApiOperation("取消订单")
    public Result cancel(@PathVariable Long id) throws Exception{
        orderService.userCancelById(id);
        return Result.success();
    }

    /** @author ZXX-挚爱
    * @Description 再来一单
    * @Dete 23:50 2023/6/15
    * @Param [id]
    * @return com.sky.result.Result
    **/

    @PostMapping("/repetition/{id}")
    @ApiOperation("再来一单功能接口")
    public Result  repetition(@PathVariable Long id){
        orderService.repetition(id);
        return Result.success();
    }

    /** @author ZXX-挚爱
    * @Description 来单提醒
    * @Dete 23:53 2023/6/15
    * @Param [id]
    * @return com.sky.result.Result
    **/

    @GetMapping("/reminder/{id}")
    @ApiOperation("来单提醒")
    public Result reminder(@PathVariable Long id){
        orderService.reminder(id);
        return Result.success();
    }
}
